/* kmeans.h
 * Zhihui Liu, last modify 20180202
 * init from Ethan Brodsky October 2011
 */

#ifndef __H_ML_KMEANS_H__
#define __H_ML_KMEANS_H__

#define MAX_CLUSTERS 10
#define MAX_DIM		10
	
struct kmeans_percentile {
	//q4 = q1 - 1.5 *(q3 - q1)
	//q5 = q3 + 1.5 *(q3 - q1)
	//q6 = q1 - 3 *(q3 - q1)
	//q7 = q1 + 3 *(q3 - q1)
	double q1, q2, q3, q4, q5, q6, q7;
    double quantile[11];
};

typedef struct _kmeans_cluster_t {
    double center[MAX_DIM];
    struct kmeans_percentile dist;
    int sample_count;
} kmeans_cluster_t;;

typedef struct _kmeans_dim_t{
    double mean;
    double enlarge_factor;
} kmeans_dim_t;

typedef struct _kmeans_model_t {
	int dim;
	int n_cluster;
	int sample_cnt;
    kmeans_cluster_t clusters[MAX_CLUSTERS];
    kmeans_dim_t dims[MAX_DIM];
} kmeans_model_t;

/*
 * PARAMS:
 *	dim: dimension of data
 *	X: pointer to data
 *	n: number of elements
 *	m: the trained model
 *	best_n_cluster: set cluster count manually. set to 0 for auto compute cluster count
 *
 * Return: 0 for success
**/
int kmeans_train(int dim, double *X, int n, kmeans_model_t *m, int best_n_cluster);

/*
 * PARAMS:
 *	m: the trained model
 *	n: number of elements
 *	sample: check samples
 *
 * Return: anomaly sample count
 *
 */
int kmeans_check(kmeans_model_t  *m, int n, double *sample, double potential, double definate, int type);

#endif



